const express = require('express');
const router = express.Router();
const db = require('../db.js');
//获取cet4词库
router.get('/cet4',(req,res)=>{
  let sql = db.cet4();
  db.Query(sql).then(data=>{
    //在数据控能够查找到结果时，将token发送给前台
    if(data.length){
      console.log('获取cet4词库成功');
      res.send({"code":"200","sucess":"获取成功！","data":data});
    }else{
      res.send({"code":"401","error":"获取失败"});
    }
    },err=>{
    res.send({"code":"401","error":"获取失败"});
  })
})
//获取cet6词库
router.get('/cet6',(req,res)=>{
  let sql = db.cet6();
  db.Query(sql).then(data=>{
    //在数据控能够查找到结果时，将token发送给前台
    if(data.length){
      console.log('获取cet6词库成功');
      res.send({"code":"200","sucess":"获取成功！","data":data});
    }else{
      res.send({"code":"401","error":"获取失败"});
    }
    },err=>{
    res.send({"code":"401","error":"获取失败"});
  })
})
//更新单词熟练度
router.post('/updateCet',(req,res)=>{
  let engOrId=req.body.engOrId;
  let degree = req.body.degree;
  let sql=db.updateCet(engOrId,degree);
  db.Query(sql).then(data=>{

      console.log('更改熟练度成功！');
      res.send({"code":"200","sucess":"更改成功"});
    },err=>{
    res.send({"code":"401","error":"更改失败！"});
  })
});
console.log('personal接口就绪');
module.exports = router;